<?php
namespace app\modules\admin\models;

use yii\db\ActiveRecord;

class AdminUser extends ActiveRecord{
    public $password2;//用于判断两次输入的密码

    public static function tableName()
    {
        return '{{AdminUser}}';
    }

    public function scenarios()
    {
        return [
            'login' => ['email','password','verifyCode'],
            'forget' => ['email','password','verifyCode','password2'],
        ];
    }

    public function rules()
    {
        return [
            [['email','password','password2','verifyCode'],'required','message'=>'内容不能为空','on'=>['login','forget']],
            ['email','email','message'=>'邮箱格式不正确','on'=>['login','forget']],
            ['password2','compare','compareAttribute'=>'password','message'=>'两次输入密码不一致','on'=>'forget'],
            ['verifyCode', 'captcha','message'=>'验证码输入错误','captchaAction'=>'/admin/login/captcha','on'=>['login','forget']],
        ];
    }

//    public function login($data){
//        //登录状态数据检测压入
//        if($this->load($data) && $this->validate()){
//            $model = self::find()->where('email=:email and password=:password',[':email'=>$this->email,':password'=>$this->password])->all();
//            if($model){
//                $session = Yii::$app->session;
//                $session['User'] = [
//                    'name' => $this->email,
//                    'lifetime' => 3600,
//                ];
//                return true;
//            }
//        }
//        return false;
//    }

}